package com.poly.oss.controller;

import com.poly.common.core.domain.R;
import com.poly.common.core.web.page.TableData;
import com.poly.common.security.annotation.RequiresPermissions;
import com.poly.oss.pojo.query.ItemQuery;
import com.poly.oss.pojo.vo.BucketVO;
import com.poly.oss.pojo.vo.ItemVO;
import com.poly.oss.service.MinioService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.List;


/**
 * Minio对象存储端点
 */
@Api("文件管理")
@RestController
@AllArgsConstructor
@RequestMapping("/minio")
public class MinioController {

    private final MinioService minioService;

    /**
     * 获取桶列表
     */
    @ApiOperation("获取桶列表")
    @RequiresPermissions("system:oss:list")
    @GetMapping("/list")
    public R<List<BucketVO>>getBucketList() {
        return R.ok(minioService.getBucketList());
    }


    /**
     * 获取桶下文件列表
     */
    @ApiOperation("获取桶下文件列表")
    @RequiresPermissions("system:oss:list")
    @GetMapping("/{bucketName}/list")
    public TableData<ItemVO> getItemList(@PathVariable("bucketName") String bucketName, ItemQuery query) {
        return minioService.getItemList(bucketName, query);
    }


    /**
     * 删除桶下文件
     */
    @ApiOperation("删除桶下文件")
    @RequiresPermissions("system:oss:remove")
    @DeleteMapping("/{bucketName}/remove")
    public R getItemList(@PathVariable("bucketName") String bucketName,@RequestBody List<String> fileNameList) {
        return R.ok(minioService.remove(bucketName, fileNameList));
    }

}
